<?php
/**
 * @Copyright Copyright (C) 2010-2012
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 + Created by:          Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webits.asia, developer@webits.asia
 * Created on:	Mar 21, 2012
 ^
 + Project: 		WRecruit
 * File Name:	views/employer/tmpl/job_appliedapplications.php
 ^ 
 * Description: template view for my job applied application
 ^ 
 * History:		NONE
 ^ 
 */
 
 defined('_JEXEC') or die('Restricted access');
 JHTML::_('behavior.formvalidation');
 
 global $mainframe;
$version = new JVersion;
$joomla = $version->getShortVersion();
$jversion = substr($joomla,0,3);

 $document =& JFactory::getDocument();
 $document->addStyleSheet('components/com_wrecruit/css/'.$this->config['theme']);
$document->addStyleSheet('components/com_wrecruit/css/wrecruitresumerating.css');
if(isset($this->resume[0]))$link = 'index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=job_appliedapplications&bd='.$this->resume[0]->id.'&Itemid='.$this->Itemid;

$actions = array(
	'0' => array('value' => 1,'text' => JText::_('JS_SHORT_LIST')),
	'1' => array('value' => 2,'text' => JText::_('JS_SEND_MESSAGE')),
	'2' => array('value' => 3,'text' => JText::_('JS_FOLDER')),
        '3' => array('value' => 4,'text' => JText::_('JS_COMMENTS'))
        );
$actioncombo = JHTML::_('select.genericList', $actions, 'action', 'class="inputbox" '. '', 'value', 'text', '');
?>

<?php if ($this->config['offline'] == '1'){ ?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" >
	<tr><td valign="top" class="<?php echo $this->theme['title']; ?>" >	<?php echo $this->config['title']; ?></td></tr>
	<tr><td height="25"></td></tr>
	<tr><td class="wrecruitmsg">
		<?php echo $this->config['offline_text']; ?>
	</td></tr>
</table>	
<?php }else{ ?>

<table cellpadding="0" cellspacing="0" border="0" width="100%" >
	<tr><td valign="top" class="<?php echo $this->theme['title']; ?>" >	
		<?php echo $this->config['title']; ?>
	</td>
	</tr>
	<tr><td height="23"></td></tr>
	<?php if ($this->config['cur_location'] == 1) {?>
	<tr><td class="curloc">
		<?php echo JText::_('JS_CUR_LOC'); ?> : <a href="index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=alljobsappliedapplications&Itemid=<?php echo $this->Itemid; ?>" class="curloclnk"><?php echo JText::_('JS_APPLIED_RESUME'); ?></a> > <?php echo JText::_('JS_JOB_APPLIED_APPLICATIONS'); ?>
	</td></tr>
	<?php } ?>
	<tr><td>
		<?php 
			if (sizeof($this->employerlinks) != 0){
				echo '<div id="toplinks"><ul>';
				foreach($this->employerlinks as $lnk)	{ ?>
					<span <?php if($lnk[2] == 1)echo 'class="first"'; elseif($lnk[2] == -1)echo 'class="last"';  ?>>
						<a href="<?php echo $lnk[0]; ?>"> <?php echo $lnk[1]; ?></a>
					</span>
				<?php }
				echo '<ul></div>';			
			}
		?>
	</td></tr>	
	<tr><td height="3"></td></tr>
	<tr><td class="<?php echo $this->theme['heading']; ?>" align="center">
		<?php echo JText::_('JS_JOB_APPLIED_APPLICATIONS'); ?>
	</td></tr>
	<tr><td height="3"></td></tr>
</table>
<?php
if ($this->resume) {  
if ($this->userrole->rolefor == 1) {  // employer

	if ($this->sortlinks['sortorder'] == 'ASC')
		$img = "components/com_wrecruit/images/sort0.png";
	else
		$img = "components/com_wrecruit/images/sort1.png";
?>
<form action="index.php" method="post" name="adminForm" id="adminForm" >
	<table cellpadding="1" cellspacing="0" border="0" width="100%">
		<?php  $exportlink='index.php?option=com_wrecruit&c=wrecruit&task=exportresume&bd='.$this->jobid;?>
		<tr >
			<td align="right" colspan="8"><a  href="<?php echo $exportlink; ?>" ><?php echo JText::_('JS_EXPORT_RESUME'); ?></a></td>
		</tr>
		<tr  class="<?php echo $this->theme['sortlinks']; ?>" height="17" valign="center">
			<td><strong><a class="<?php echo $this->theme['sortlinks']; ?>" href="<?php echo $link?>&sortby=<?php echo $this->sortlinks['name']; ?>"><?php echo JText::_('JS_NAME'); ?></a></strong><?php if ($this->sortlinks['sorton'] == 'name') { ?> <img src="<?php echo $img ?>"> <?php } ?></td>
			<td><strong><a class="<?php echo $this->theme['sortlinks']; ?>" href="<?php echo $link?>&sortby=<?php echo $this->sortlinks['gender']; ?>"><?php echo JText::_('JS_GENDER'); ?></a></strong><?php if ($this->sortlinks['sorton'] == 'gender') { ?> <img src="<?php echo $img ?>"> <?php } ?></td>
			<td align="center"><strong><a class="<?php echo $this->theme['sortlinks']; ?>" href="<?php echo $link?>&sortby=<?php echo $this->sortlinks['jobsalaryrange']; ?>"><?php echo JText::_('JS_SALARY'); ?></a></strong><?php if ($this->sortlinks['sorton'] == 'jobsalaryrange') { ?> <img src="<?php echo $img ?>"> <?php } ?></td>
			<td align="center"><strong><a class="<?php echo $this->theme['sortlinks']; ?>" href="<?php echo $link?>&sortby=<?php echo $this->sortlinks['apply_date']; ?>"><?php echo JText::_('JS_APPLIED_DATE'); ?></a></strong><?php if ($this->sortlinks['sorton'] == 'apply_date') { ?> <img src="<?php echo $img ?>"> <?php } ?></td>
			<td align="center"><strong><a class="<?php echo $this->theme['sortlinks']; ?>" href="<?php echo $link?>&sortby=<?php echo $this->sortlinks['total_experience']; ?>"><?php echo JText::_('JS_EXPERIENCE'); ?></a></strong><?php if ($this->sortlinks['sorton'] == 'total_experience') { ?> <img src="<?php echo $img ?>"> <?php } ?></td>
			<td class="<?php echo $this->theme['sortlinks']; ?>"><strong>	</strong></td>
			<td class="<?php echo $this->theme['sortlinks']; ?>"><strong>	</strong></td>
		</tr>
		<tr>
		<td colspan="5"></td>
		</tr>
			<?php 
		$tdclass = array($this->theme['odd'], $this->theme['even']);
		$isodd =1;
                $count = 0;
		if ( isset($this->resume) ){
                    foreach($this->resume as $app)	{
                            $count++;
                            $isodd = 1 - $isodd; ?>
						<tr class="<?php echo $tdclass[$isodd]; ?>">
                            <td ><?php if ($app->resumeview == 0) echo '<strong>'; ?><?php echo $app->first_name.' '.$app->last_name; ?><?php if ($app->resumeview == 0) echo '</strong>'; ?></td>
                            <td ><?php if($app->gender==1) echo JText::_('JS_MALE');
                                                    elseif($app->gender==2) echo JText::_('JS_FEMALE');
                                                    else  echo JText::_('JS_DOES_NOT_MATTER')?></td>
                            <td ><?php echo $app->symbol . $app->rangestart . ' - ' . $app->symbol.' '. $app->rangeend; ?></td>
                            <td ><?php echo date($this->config['date_format'],strtotime($app->apply_date)); ?></td>
                            <td align="center"><?php echo $app->total_experience;  ?></td>
                            <td ><input type="button" class="button" onclick='getjobdetail("resumedetail_<?php echo $app->appid; ?>",<?php echo $app->id; ?>,<?php echo $app->appid; ?>)' value="<?php echo JText::_('JS_DETAILS'); ?>"></td>
                            <td nowrap="nowrap" >
                                    <?php $link = 'index.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=view_resume&vm=2&rd='.$app->appid.'&bd='.$app->id.'&Itemid='.$this->Itemid; ?> 
									<a class="pageLink" href="<?php echo $link?>"><?php echo JText::_('JS_RESUME');?></a> 
									<?php if($jversion == '1.5' ){ ?>
										<?php $plink = 'index2.php?option=com_wrecruit&c=wrecruit&view=jobseeker&layout=resume_print&vm=2&rd='.$app->appid.'&bd='.$app->id.'&Itemid='.$this->Itemid; ?> 
										<a  href="<?php echo $plink?>"><img src="components/com_wrecruit/images/print.png"/> </a>
									<?php } ?>
                            </td>
                        </tr>
                        <tr class="<?php echo $tdclass[$isodd]; ?>">
                            <td>
                                <strong><?php echo JText::_('JS_COMMENTS'); ?></strong>
                            </td>
                            <td colspan="4">
                                <div>
                                    <?php echo  $app->comments; ?>
                                </div>
                            </td>
                                    <td colspan="3">
                                        <div>
                                        <?php
                                            $id = $app->jobapplyid;
                                            $percent = 0;
                                            $stars = '';
                                            $percent = $app->rating * 20;
                                            $stars = '-small';
                                            $html="
                                                <div class=\"wrecruit-container".$stars."\"".( " style=\"margin-top:5px;\"" ).">
                                                <ul class=\"wrecruit-stars".$stars."\">
                                                <li id=\"rating_".$id."\" class=\"current-rating\" style=\"width:".(int)$percent."%;\"></li>
                                                <li><a href=\"javascript:void(null)\" onclick=\"javascript:setrating('rating_".$id."',1,".(int)$app->ratingid.",".$app->id.",".$app->appid.");\" title=\"".JTEXT::_('Very Poor')."\" class=\"one-star\">1</a></li>
                                                <li><a href=\"javascript:void(null)\" onclick=\"javascript:setrating('rating_".$id."',2,".(int)$app->ratingid.",".$app->id.",".$app->appid.");\" title=\"".JTEXT::_('Poor')."\" class=\"two-stars\">2</a></li>
                                                <li><a href=\"javascript:void(null)\" onclick=\"javascript:setrating('rating_".$id."',3,".(int)$app->ratingid.",".$app->id.",".$app->appid.");\" title=\"".JTEXT::_('Regular')."\" class=\"three-stars\">3</a></li>
                                                <li><a href=\"javascript:void(null)\" onclick=\"javascript:setrating('rating_".$id."',4,".(int)$app->ratingid.",".$app->id.",".$app->appid.");\" title=\"".JTEXT::_('Good')."\" class=\"four-stars\">4</a></li>
                                                <li><a href=\"javascript:void(null)\" onclick=\"javascript:setrating('rating_".$id."',5,".(int)$app->ratingid.",".$app->id.",".$app->appid.");\" title=\"".JTEXT::_('Very Good')."\" class=\"five-stars\">5</a></li>
                                                </ul>
                                                </div>
                                            ";
                                            $html .="</small></span>";
                                            echo $html;
                                        ?>
                                        </div>
                                    </td>

                        </tr>
                        <tr class="<?php echo $tdclass[$isodd]; ?>">
                            <td>
                                <strong><?php echo JText::_('JS_LOCATION'); ?></strong>
                            </td>
                            <td colspan="3" align="left">
                                <?php
                                	$comma = 0;
                                    if ($app->cityname) { echo $app->cityname; $comma = 1; }
                                    elseif ($app->address_city) { echo $app->address_city; $comma = 1; }
                                    if ($app->countyname) { if($comma) echo', '; echo $app->countyname; $comma = 1; }
                                    elseif ($app->address_county) { if($comma) echo', '; echo $app->address_county; $comma = 1; }
                                    if ($app->statename) { if($comma) echo', '; echo $app->statename; $comma = 1; }
                                    elseif ($app->address_state) { if($comma) echo', '; echo $app->address_state; $comma = 1; }
                                    if ($app->countryname) { if($comma) echo', '; echo $app->countryname; $comma = 1; }
                                 ?>
                            </td>
                            <td colspan="4" align="center">
                                <?php echo JText::_('JS_ACTION').'&nbsp;&nbsp;&nbsp;'.JHTML::_('select.genericList', $actions, 'action_'.$count, 'class="inputbox" '. '', 'value', 'text', '');; ?>&nbsp;&nbsp;&nbsp;
                                <input type="button" class="button" onclick="actioncall(<?php echo $app->jobapplyid; ?>,<?php echo $app->id; ?>,<?php echo $app->appid; ?>,'<?php echo "action_$count"; ?>')" value="<?php echo JText::_('JS_GO'); ?>">
                            </td>
                        </tr>
                        <tr><td  id="resumeaction_<?php echo $app->jobapplyid; ?>" colspan="8"></td></tr>
                        <tr><td  id="resumedetail_<?php echo $app->appid; ?>" colspan="8"></td></tr>


                    <tr><td height="15"></td></tr>

                    <?php
                    }
		}
		?>
		</table>


			<input type="hidden" name="task" id="task" value="saveshortlistcandiate" />
			<input type="hidden" name="Itemid" id="Itemid" value="<?php echo $this->Itemid; ?>" />
			<input type="hidden" name="jobid" id="jobid" value="<?php echo $app->id; ?>" />
			<input type="hidden" name="resumeid" id="resumeid" value="<?php echo $app->appid; ?>" />
			<input type="hidden" name="id" id="id" value="" />
			<input type="hidden" name="action" id="action" value="" />
			<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
		
		
		
		
		
		
		
		</form>

<form action="<?php echo JRoute::_('index.php?option=com_wrecruit&c=wrecruit&view=employer&layout=job_appliedapplications&bd='.$this->resume[0]->id.'&Itemid='.$this->Itemid); ?>" method="post">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td></td>
        <td >
            <?php
            echo $this->pagination->getPagesLinks();
            ?>
        </td>
    </tr>
    <tr>
        <td align="left">
            <?php echo JText::_('JS_DISPLAY_#'); ?>
            <?php
            echo $this->pagination->getLimitBox();
            ?>
        </td>
        <td align="right">
            <?php
            echo $this->pagination->getResultsCounter();
            ?>
        </td>
    </tr>
</table>
<script language=Javascript>
function actioncall(jobapplyid,jobid, resumeid, action){
        actionvalue = document.getElementById(action).value;
        if(actionvalue == 3){ // folder
            getfolders('resumeaction_'+jobapplyid,jobid,resumeid,jobapplyid);
        }else if(actionvalue == 4){ // comments
            getresumecomments('resumeaction_'+jobapplyid,jobapplyid);
        }else{
            document.getElementById('resumeid').value=resumeid;
            document.getElementById('action').value=actionvalue;
            document.forms["adminForm"].submit();
        }
}
function setresumeid(resumeid, action){
        document.getElementById('resumeid').value=resumeid;
        document.getElementById('action').value=document.getElementById(action).value;
        document.forms["adminForm"].submit();
}
function saveresumecomments(jobapplyid){
        document.getElementById('id').value=jobapplyid;
        document.getElementById('task').value='saveresumecomments';
        document.forms["adminForm"].submit();
}
function saveaddtofolder(jobid,resumeid){
        document.getElementById('resumeid').value=resumeid;
         document.getElementById('jobid').value=jobid;
        document.getElementById('task').value='saveresumefolder';
        document.forms["adminForm"].submit();
}
function getfolders(src,jobid,resumeid,applyid){
    	//var pagesrc = 'jobdetail_'+src;
	document.getElementById(src).innerHTML="Loading ...";
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e)
	{
		try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
		catch (e2)
		{
		  try {  xhr = new XMLHttpRequest();     }
		  catch (e3) {  xhr = false;   }
		}
	 }

	xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
        	document.getElementById(src).innerHTML=xhr.responseText; //retuen value

      }
    }

	xhr.open("GET","index.php?option=com_wrecruit&task=getmyforlders&jobid="+jobid+"&resumeid="+resumeid+"&applyid="+applyid,true);
	xhr.send(null);
}
function getresumecomments(src,jobapplyid){
    	//var pagesrc = 'jobdetail_'+src;
	document.getElementById(src).innerHTML="Loading ...";
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e)
	{
		try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
		catch (e2)
		{
		  try {  xhr = new XMLHttpRequest();     }
		  catch (e3) {  xhr = false;   }
		}
	 }

	xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
        	document.getElementById(src).innerHTML=xhr.responseText; //retuen value

      }
    }
    //alert('abc');
    xhr.open("GET","index.php?option=com_wrecruit&task=getresumecomments&jobapplyid="+jobapplyid,true);
	xhr.send(null);
}
function getjobdetail(src,jobid, resumeid){
    	//var pagesrc = 'jobdetail_'+src;
	document.getElementById(src).innerHTML="Loading ...";
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e)
	{
		try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
		catch (e2)
		{
		  try {  xhr = new XMLHttpRequest();     }
		  catch (e3) {  xhr = false;   }
		}
	 }

	xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
        	document.getElementById(src).innerHTML=xhr.responseText; //retuen value

      }
    }

	xhr.open("GET","index.php?option=com_wrecruit&task=getresumedetail&jobid="+jobid+"&resumeid="+resumeid,true);
	xhr.send(null);
}

function clsjobdetail(src){
        document.getElementById(src).innerHTML="";

}
function clsaddtofolder(src){
        document.getElementById(src).innerHTML="";
}
function setrating(src,newrating,ratingid,jobid,resumeid){
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e)
	{
		try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
		catch (e2)
		{
		  try {  xhr = new XMLHttpRequest();     }
		  catch (e3) {  xhr = false;   }
		}
	 }

	xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 && xhr.status == 200){
               if(xhr.responseText == 1)
                document.getElementById(src).style.width=parseInt(newrating*20)+'%';

      }
    }

	xhr.open("GET","index.php?option=com_wrecruit&task=saveresumerating&ratingid="+ratingid+"&jobid="+jobid+"&resumeid="+resumeid+"&newrating="+newrating,true);
	xhr.send(null);


}

</script>

</form>	
<?php

} else{ // not allowed job posting
echo JText::_('JS_YOU_ARE_NOT_ALLOWED_TO_VIEW');
}	
}else{ // no result found in this category
	echo JText::_('JS_RESULT_NOT_FOUND');
}
}//ol
?>	
<div width="100%">
<?php 
if($this->config['fr_cr_txsh']) {
	echo 
	'<table width="100%" style="table-layout:fixed;">
		<tr><td height="15"></td></tr>
		<tr><td style="vertical-align:top;" align="center">'.$this->config['fr_cr_txa'].$this->config['fr_cr_txb'].'</td></tr>
	</table>';
}	
?>
</div>


